package com.liu.juc.pool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * 线程池的了解
 * 3大方法
 */
public class ThreadPoolDemo1 {
    /**
     * newSingleThreadExecutor: 只有一个线程，线程大小为1
     * newFixedThreadPool  :自定义线程多少
     * newCachedThreadPool : 伸缩线程
     *
     * @param args
     */
    public static void main(String[] args) {
        //ExecutorService executorService = Executors.newSingleThreadExecutor();
        //ExecutorService executorService = Executors.newFixedThreadPool(5);
        ExecutorService executorService = Executors.newCachedThreadPool();
        try {
            for (int i = 0; i < 6; i++) {
                executorService.execute(() -> {
                    System.out.println(Thread.currentThread().getName() + "--- ok");
                });
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            //关闭线程池
            executorService.shutdown();
        }


    }
}
